package com.youi.manage;


import com.youi.common.SessionKey;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * session工具
 *
 * @author erdong.Chan
 */
public class HttpSessionManage {


    /**
     * 用户退出登录
     */
    public static void userLoginOut(HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        session.removeAttribute(SessionKey.USER);
    }

    /**
     * 管理员退出登录
     */
    public static void sysUserLoginOut(HttpServletRequest request) {
        // 防止创建Session
        HttpSession session = request.getSession(false);
        session.removeAttribute(SessionKey.SYSUSER);
    }

    /**
     * 获取SessionID
     *
     * @param request
     * @return
     */
    public static String getSessionId(HttpServletRequest request) {
        return request.getSession().getId();
    }

    /**
     * session中保存对象
     */
    public static void setAttribute(HttpServletRequest request, String name, Object value) {
        HttpSession session = request.getSession();
        session.setAttribute(name, value);
    }

    /**
     * 获取session中保存的对象
     */
    public static Object getAttribute(HttpServletRequest request, String name) {
        HttpSession session = request.getSession();
        return session.getAttribute(name);
    }

    /**
     * 删除
     */
    public static void removeAttribute(HttpServletRequest request, String name) {
        HttpSession session = request.getSession();
        session.removeAttribute(name);
    }

}
